public class chap2_1 {
    public static <T extends Comparable> void MergeList_Sq(sequenceList<T> LA,sequenceList<T> LB,sequenceList<T> LC){
        /*已知顺序线性表LA和LB的元素按值非递减排列，归并LA和LB得到新的顺序线性表LC，LC的元素也安置非递减排列*/
        int i=1,j=1,k=1;
        while(i<=LA.size() && j<= LB.size()){
            if (LA.value(i).compareTo(LB.value(j))<=0){
                LC.add(LA.value(i),k);
                i++;
            }else{
                LC.add(LB.value(j),k);
                j++;
            }
            k++;
        }
        while (i< LA.size()){
            LC.add(LA.value(i),k);
            i++;
            k++;
        }
        while (j<=LB.size()){
            LC.add(LB.value(j),k);
            j++;
            k++;
        }
    }
    public static void main(String[] args){
        int i,j,k=0;
        int[] a = {12,23,35,49,56};
        int[] b = {10,15,20};
        sequenceList<Integer> La = new sequenceList<>();
        sequenceList<Integer> Lb = new sequenceList<>();
        sequenceList<Integer> Lc = new sequenceList<>();
        for (i=0;i<a.length;i++){
            La.add(a[i],i+1);
        }
        System.out.println("顺序表a中的元素：");
        La.nextOder();
        for (j=0;j<b.length;j++){
            Lb.add(b[j],j+1);
        }
        System.out.println("顺序表b中的元素：");
        Lb.nextOder();
        MergeList_Sq(La,Lb,Lc);
        System.out.println("顺序表C中的数据元素为：");
        Lc.nextOder();

    }
}
